package com.bulletelc.apollopre.module.main.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.Classify;
import com.bulletelc.apollopre.manager.imageload.ImageLoaderManager;

import java.util.List;

/**
 * author: lhl
 * date  : 2018/01/13
 * desc  : 一级分类的adapter
 */

public class HomeClassifyFirstAdapter extends BaseAdapter {
    private Context context;
    private List<Classify> classifyList;
    private LayoutInflater inflater;

    public HomeClassifyFirstAdapter(Context context, List<Classify> classifyList) {
        this.context = context;
        this.classifyList = classifyList;
        this.inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return classifyList!=null?classifyList.size():0;
    }

    @Override
    public Object getItem(int position) {
        return classifyList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Classify classify = classifyList.get(position);
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.home_classify_first_item,parent,false);
            holder = new ViewHolder();
            holder.tvClassifyFirstName = convertView.findViewById(R.id.tvClassifyFirstName);
            holder.ivClassifyFirstImg = convertView.findViewById(R.id.ivClassifyFirstImg);
            holder.llItem = convertView.findViewById(R.id.llItem);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ImageLoaderManager.getInstance().loadImage(ImageLoaderManager.getDefaultOptions(holder.ivClassifyFirstImg, classify.getImageUrl()));
        //holder.tvClassifyFirstName.setText(classify.getName());

        return convertView;
    }

    class ViewHolder{
        ImageView ivClassifyFirstImg;
        TextView tvClassifyFirstName;
        LinearLayout llItem;
    }
}
